package com.sy.simpleegg.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.sy.simpleegg.R
import com.sy.simpleegg.bean.CashGoodBean
import com.sy.simpleegg.config.Config
import com.sy.simpleegg.constant.ProductType
import com.sy.simpleegg.databinding.ItemCashGoodBinding
import com.sy.simpleegg.util.BigDecimalUtil

class CashGoodAdapter(val context: Context, val cashGoods: MutableList<CashGoodBean>):
    RecyclerView.Adapter<CashGoodAdapter.ViewHolder>() {
        
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CashGoodAdapter.ViewHolder {
        val binding = ItemCashGoodBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return cashGoods.size
    }

    @SuppressLint("RecyclerView", "SetTextI18n")
    override fun onBindViewHolder(holder: CashGoodAdapter.ViewHolder, position: Int) {
        val item = cashGoods[position]
        holder.itemName.text = "${BigDecimalUtil.getPrice(item.price)}" +
//                context.getString(R.string.amount_unit) +
                Config.CURRENCY_SYMBOLS +
                "=" +
                item.value +
                when (Config.PRODUCT_TYPE){
                    ProductType.CURRENCY -> context.getString(R.string.bi)
                    ProductType.BEAD -> context.getString(R.string.bead)
                } + if (item.flag.isNullOrEmpty() || item.flag == "0") "" else "(${context.getString(R.string.donate)}+${item.flag})"
    }

    private fun refreshTab(position: Int){

    }

    inner class ViewHolder(binding: ItemCashGoodBinding): RecyclerView.ViewHolder(binding.root){
        val itemName: TextView = binding.tvCoins
    }
}